package com.woniu.adopt_web.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.adopt_web.entity.Activity;
import com.woniu.adopt_web.entity.Pet;
import com.woniu.adopt_web.mapper.CommentMapper;
import com.woniu.adopt_web.vo.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {


    @Autowired
    CommentMapper commentMapper;

    public PageInfo<CommentVo> queryAllByPage(Integer now , Integer size){
        PageHelper.startPage(now ,size);
        List<CommentVo> commentVos = commentMapper.selectAllByDel();
        return new PageInfo<>(commentVos);
    }

    public PageInfo<Pet> queryPetAllByPage(Integer now , Integer size){
        PageHelper.startPage(now ,size);
        List<Pet> pets = commentMapper.selectPetAllByDel();
        return new PageInfo<>(pets);
    }

    public List<CommentVo> selectCommentByPetKey(int id) {

        List<CommentVo> commentVos = commentMapper.selectAllCommentByPid(id);
        for (CommentVo c :commentVos){
            if(c.getAnswerUser() == null){
                c.setAnswerUser("");
            }
        }
        return commentVos;
    }

    public int insertCommentByUIdAndPid(CommentVo commentVo) {

        return commentMapper.addCommentByUidAndPid(commentVo);
    }
}
